﻿using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WebApi.Models;

namespace WebApi.Bill.Biz
{
    public class BizTopic : BizBase
    {
        readonly string tb = "TbTopic";
        readonly string pk = "pkId";


        public TopicModel Get(int code)
        {
            return Db.GetModel<TopicModel>(x => x.Code == code);

        }

        public void Update(TopicModel model)
        {
            Db.UpdateModel<TopicModel>(model);
        }

        public int Add(TopicModel model)
        {
            return Db.InsertModel<TopicModel>(model);
        }


        #region 获取当前议题信息列表

        /// <summary>
        /// 获取当前议题信息列表
        /// </summary>
        /// <param name="pageNum">当前页码</param>
        /// <param name="pageSize">每页显示条数</param>
        /// <param name="recordCount">总列数</param>
        /// <returns></returns>
        public List<TopicModel> GetPageList(dynamic data, ref int recordCount, ref int totalPage)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append($"select * from {this.tb} where 1=1  ");
            JObject joFilters = FiltersSql.GetQueryCond(data);
            sb.Append(joFilters["sqlAppend"].ToString());
            sb.Append($" order by tCreate");
            int pageNum = Convert.ToInt32(joFilters["pageNum"]);
            int pageSize = Convert.ToInt32(joFilters["pageSize"]);
            return Da.PageList<TopicModel>(sb.ToString(), pageNum, pageSize, ref recordCount, ref totalPage);
        }


        #endregion

    }
}
